@extends('layout.admin.master')
@section('content')
    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-tabs-sm">
                <li class="nav-item">
                    <a href="{{route('news.lists')}}" class="nav-link active">
                        新闻列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{route('news.news.create')}}" class="nav-link ">
                        添加新闻
                    </a>
                </li>
            </ul>
        </div>
    </div>

        <div class="card">
            <div class="card-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>标题</th>
                        <th>作者</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($news as $new)
                    <tr>
                        <td scope="row">{{$new->id}}</td>
                        <td>{{$new->title}}</td>
                        <td>{{$new->auth}}</td>
                        <td>
                            <a href="{{route('news.news.show',$new)}}" class="btn btn-info btn-sm">查看</a>
                            <a href="{{route('news.news.edit',$new)}}" class="btn btn-primary btn-sm">编辑</a>
                            <a href="javascript:;" onclick="del(this)" class="btn btn-danger btn-sm">删除</a>
                            <form action="{{route('news.news.destroy',$new)}}" method="post">
                                @csrf @method('DELETE')
                            </form>
                        </td>
                    </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        <div class="card-footer text-muted">

        </div>

@endsection
@push('js')
    <script>
        function del(obj) {
            require(['https://unpkg.com/sweetalert/dist/sweetalert.min.js'],function (swal) {
                swal({
                    title: "确认删除?",
                    icon: "warning",
                    buttons: '确定',
                    dangerMode: '取消',
                })
                    .then((willDelete) => {
                        if (willDelete) {
                            $(obj).next('form').submit();
                        } else {
                            return false
                        }
                    });
            })
        }
    </script>
    @endpush